﻿@model  RBAC.Web.Models.FunctionModel
@using RBAC.Web.CustomHelpers
@using RBAC.Web.Mapper
@using RBAC.Web.Utilities
@{
    ViewBag.Title = "Edit Function";

			string returnUrl = "";
				
																			string DomainName = "";
					if (TempData["DomainLookupField"] == null || String.IsNullOrEmpty(TempData["DomainLookupField"].ToString()))
					{
						returnUrl = Url.Action("ListFunction", "Function");
					}
					else
					{
						DomainName = TempData["DomainLookupField"].ToString();
						returnUrl = Url.Action("EditDomain", "Domain", new { DomainName = DomainName });
					}  
																							 
	}
@section Styles {
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/form.js?3")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet" type="text/css" />

	<link href="@Url.Content("~/Content/bootstrap/css/utility.css")" rel="stylesheet"		type="text/css">

    <script type="text/javascript">
        $(function () {
            //How to setup Datepicker
			            SetDatePicker("FreeDate");
            
			//How to setup Lookup
							SetExternalLookupFor("Function_Domain", "Function_DomainGetExternalLookup", 
                "Function_DomainPopExternalLookup", 'Function_Domain|Function_DomainLookupField');
			
							SetExternalLookupFor("Function_DomainLookup", "Function_DomainLookupGetExternalLookup", 
                "Function_DomainLookupPopExternalLookup", 'Function_DomainLookup|Function_DomainLookupLookupField|DomainLookupId');
			
			
			//Master Detail
			 
							 
							 
							 
							 
							 
							 
							        });
    </script>
}


	<div class="row">
        <div class="col-lg-12">
             <h2 class="page-header">Function</h2>
        </div>
    </div> 

@using (Html.BeginForm("Update", "Function", FormMethod.Post, new { @id = "form-Function",@class = "form-horizontal", role = "form"  }))
{
    
   
	//version 1.4 Bootstrap 7/4/2557
<div class="panel panel-primary">
	<div class="panel-heading">FunctionModel</div>
	<div class="panel-body">
    

																								@Html.Hidden("Parent_DomainDomainName", @DomainName)
																																
	
      
				@Html.HiddenFor(model => model.Id)
						
		   <div class="form-group row">	   

      									 
			
												<div class="col-md-6">
                 <div class="col-md-4">
				<label class = "word-control-res">@Html.LabelFor(model => model.FuncName)</label>
				</div>
			    <div class="col-md-8">
                @Html.TextBoxFor(model => model.FuncName, new{@class="form-control"})
				
				 </div>
				 <div class="col-md-offset-4 col-md-8">
				   @Html.ValidationMessageFor(model => model.FuncName)
				</div>
				</div>
									@Html.HiddenFor(model => model.Id)
					<input type="hidden" name="Mode" value="Edit" />
					<input type="hidden" name="OldValue" value="@(Model.FuncName == null ? "" : Model.FuncName )" />
						
									 
			
												<div class="col-md-6">
                 <div class="col-md-4">
				<label class = "word-control-res">@Html.LabelFor(model => model.Description)</label>
				</div>
			    <div class="col-md-8">
                @Html.TextBoxFor(model => model.Description, new{@class="form-control"})
				
				 </div>
				 <div class="col-md-offset-4 col-md-8">
				   @Html.ValidationMessageFor(model => model.Description)
				</div>
				</div>
						
																		 
			
						
            <div class="col-md-6">
                 <div class="col-md-4">
                <label class = "word-control-res">@Html.LabelFor(model => model.FunctionStatus)</label>
				</div>
			    <div class="col-md-8">
                @Html.RadioButtonForSelectList(model => model.FunctionStatus, FunctionStatusMapper.GetFunctionStatusSelectList())
                
				</div>	
				<div class="col-md-offset-4 col-md-8">
				   @Html.ValidationMessageFor(model => model.FunctionStatus)
				</div>
				</div>	
				           
						 
			
						
            
			   <div class="col-md-6">
                 <div class="col-md-4">
                <label class = "word-control-res">@Html.LabelFor(model => model.FunctionName)</label>
			   </div>
			    <div class="col-md-8">
                @Html.DropDownListWithDefaultValueFor(model => model.FunctionName, FunctionNameMapper.GetFunctionNameSelectList())
               
				</div>
				<div class="col-md-offset-4 col-md-8">
				   @Html.ValidationMessageFor(model => model.FunctionName)
				</div>
				</div>
				            
												
		</div>
		
		<div class="col-md-6">   
				<div class ="btn-group">
					<label><input type="button" name="btnBack" value="Cancel" class="btn btn-primary" id="button-back" onclick="location.href='@returnUrl'"/>   </label>
					<label><input type="Button" value="Save" id="button-save" class="btn btn-primary" onclick="JavaScript: SaveButtonClick()" />				</label>
					<label><input type="button" name="btnDelete" value="Delete" class="btn btn-primary" id="button-delete" onclick="JavaScript: DeleteButtonClick()" />  </label>
				</div>
		</div>

  


        </div>
    </div> 

// Master Detail Dest Class
															}




	<div class="modal" id="Delete">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h4 class="modal-title">Delete Function</h4>
                        </div>
                        <div class="modal-body">
                            Do you want to delete?
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" id="confirm-delete" class="btn btn-primary">YES</button>
                            <button type="button" data-dismiss="modal" class="btn btn-primary">NO</button>
                        </div>
                    </div>
                </div>
	</div>


           <div class="modal" id="Save">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h4 class="modal-title">Save Function</h4>
                        </div>
                        <div class="modal-body">
                            Do you want to save?
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" id="confirm-save" class="btn btn-primary">YES</button>
                            <button type="button" data-dismiss="modal" class="btn btn-primary">NO</button>
                        </div>
                    </div>
                </div>
            </div>

<script type="text/javascript">
	$(function () {

        $("#button-delete").click(function () {
              
          
            $('#Delete').modal('show');
            $('#confirm-delete').click(function () {
                $.post('@Url.Action("DeleteFunctionById", "Function")',$("#form-Function").serialize(),function (data) {
                    var s = '@returnUrl'
                    if(s.indexOf("?") !== -1)
                        window.location.href = s + '&result=' + data + '&operation=delete';   
                    else
                        window.location.href = s + '?result=' + data + '&operation=delete';
                });
                         
                   
            });
        });
    
 

        $("#button-save").click(function () {
            
            $('#Save').modal('show'); 
            $('#confirm-save').click(function () {
               $("#form-Function").submit();
            });
        });
    });
</script>